package com.qeeyou.apps.android.craftsman.service;

import com.google.gson.Gson;
import com.qeeyou.apps.android.craftsman.po.AreaInfo;
import com.qeeyou.apps.android.craftsman.po.CommentInfo;
import com.qeeyou.apps.android.craftsman.po.CommonInfo;
import com.qeeyou.apps.android.craftsman.po.InstallMaterialInfo;
import com.qeeyou.apps.android.craftsman.po.InstallMaterialPriceInfo;
import com.qeeyou.apps.android.craftsman.po.InstallMethodInfo;
import com.qeeyou.apps.android.craftsman.po.InstallTypeInfo;
import com.qeeyou.apps.android.craftsman.po.LatestCommentInfo;
import com.qeeyou.apps.android.craftsman.po.LatestOrderInfo;
import com.qeeyou.apps.android.craftsman.po.MasterInfo;
import com.qeeyou.apps.android.craftsman.po.MasterInfoByOrderId;
import com.qeeyou.apps.android.craftsman.po.OrderDetailInfo;
import com.qeeyou.apps.android.craftsman.po.OrderInfo;
import com.qeeyou.apps.android.craftsman.po.PushMsgInfo;
import com.qeeyou.apps.android.craftsman.po.InstallShopInfo;
import com.qeeyou.apps.android.craftsman.po.UploadImgInfo;
import com.qeeyou.apps.android.craftsman.po_wrap.AreaResultInfo;
import com.qeeyou.apps.android.craftsman.po_wrap.CommentListResultInfo;
import com.qeeyou.apps.android.craftsman.po_wrap.InstallMaterialPriceResultInfo;
import com.qeeyou.apps.android.craftsman.po_wrap.InstallMaterialResultInfo;
import com.qeeyou.apps.android.craftsman.po_wrap.InstallMethodResultInfo;
import com.qeeyou.apps.android.craftsman.po_wrap.InstallTypeResultInfo;
import com.qeeyou.apps.android.craftsman.po_wrap.LatestCommentResultInfo;
import com.qeeyou.apps.android.craftsman.po_wrap.LatestOrderResultInfo;
import com.qeeyou.apps.android.craftsman.po_wrap.MasterInfoByOrderIdResultInfo;
import com.qeeyou.apps.android.craftsman.po_wrap.MasterResultInfo;
import com.qeeyou.apps.android.craftsman.po_wrap.OrderDetailResultInfo;
import com.qeeyou.apps.android.craftsman.po_wrap.OrderResultInfo;
import com.qeeyou.apps.android.craftsman.po_wrap.PushMsgListResultInfo;
import com.qeeyou.apps.android.craftsman.po_wrap.ShopResultInfo;
import com.qeeyou.apps.android.craftsman.po_wrap.UploadImgResultInfo;
import com.qeeyou.apps.android.craftsman.utils.OKHttpUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by xuchengxiong on 2017/12/25.
 */

public class AppService {

    private static AppService instance;

    public static AppService getInstance() {
        if (instance == null) {
            instance = new AppService();
        }
        return instance;
    }

    private AppService() {

    }

    //获取最新完成的订单信息
    private String latestOrderInfoApiUrl() {
        return APIConfig.BASE_URL + "/home/getNewFinishOrder";
    }

    //获取最新评论的订单信息
    private String latestCommentInfoApiUrl() {
        return APIConfig.BASE_URL + "/home/getNewCommentOrder";
    }

    //获取首页推荐师傅列表
    private String recommendMasterListApiUrl() {
        return APIConfig.BASE_URL + "/home/homeRecommendGetMaster";
    }

    //首页消息列表
    private String getPushMessageListUrl() {
        return APIConfig.BASE_URL + "/pushmessage/getPushMessageList";
    }

    //首页签到
    private String signedInUrl() {
        return APIConfig.BASE_URL + "/my/signedIn";
    }

    //查询师傅列表
    private String searchMasterListApiUrl() {
        return APIConfig.BASE_URL + "/home/masterSearchList";
    }

    //更多师傅列表
    private String masterListApiUrl() {
        return APIConfig.BASE_URL + "/masterInfo/getMasterInfoList";
    }

    //师傅详情评论列表
    private String masterCommentListApiUrl() {
        return APIConfig.BASE_URL + "/masterInfo/getOrderInfoByMasterId";
    }

    //我的订单列表
    private String myOrderListApiUrl() {
        return APIConfig.BASE_URL + "/myorder/getMyOrderInfoList";
    }

    //取消订单
    private String cancelOrderApiUrl() {
        return APIConfig.BASE_URL + "/order/cancelOrderPay";
    }

    //订单详情
    private String orderDetailApiUrl() {
        return APIConfig.BASE_URL + "/order/getOrderDetailByOrderId";
    }

    //下单
    private String orderActionApiUrl() {
        return APIConfig.BASE_URL + "/order/placeOrder";
    }

    //安装类型
    private String installTypeListApiUrl() {
        return APIConfig.BASE_URL + "/dicservicetype/getAllServiceType";
    }

    //安装方式
    private String installMethodListApiUrl() {
        return APIConfig.BASE_URL + "/dicservicemethod/getAllServiceMethod";
    }

    //安装材料
    private String installMaterialListApiUrl() {
        return APIConfig.BASE_URL + "/dicmaterial/getAllMaterial";
    }

    //安装材料价格列表
    private String installMaterialPriceListApiUrl() {
        return APIConfig.BASE_URL + "/shop/getShopPriceList";
    }

    //安装商品列表
    private String installShopListApiUrl() {
        return APIConfig.BASE_URL + "/shop/getShopsForList";
    }

    //上传图片
    private String uploadImageUrl() {
        return APIConfig.BASE_URL + "/img/uploadImg";
    }

    //上海市所有地区
    private String getAllAreaUrl() {
        return APIConfig.BASE_URL + "/area/getAllArea";
    }

    //意见反馈
    private String feedbackApiUrl() {
        return APIConfig.BASE_URL + "/feedBack/saveFeedBack";
    }

    //根据订单id获取师傅信息
    private String getMasterInfoByOrderidUrl() {
        return APIConfig.BASE_URL + "/myorder/getMasterInfoByOrderid";
    }

    //对订单进行评价
    private String commentOrderUrl() {
        return APIConfig.BASE_URL + "/myorder/commentOrder";
    }

    //获取最新完成的订单信息
    public LatestOrderInfo getLatestOrderInfo(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = latestOrderInfoApiUrl();
                returnString = OKHttpUtil.downWithGetMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            LatestOrderResultInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, LatestOrderResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage()) ||
                    resultInfo.getResponse() == null) {
                return null;
            } else {
                return resultInfo.getResponse();
            }
        }
    }

    //获取最新评论的订单信息
    public LatestCommentInfo getLatestCommentInfo(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = latestCommentInfoApiUrl();
                returnString = OKHttpUtil.downWithGetMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            LatestCommentResultInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, LatestCommentResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage()) ||
                    resultInfo.getResponse() == null) {
                return null;
            } else {
                return resultInfo.getResponse();
            }
        }
    }

    //首页推荐师傅列表
    public List<MasterInfo> getRecommendMasterList(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        if (token != null) {
            headerMap.put("token", token);
        }
        String userId = SystemContext.getInstance().getUserId();
        if (userId != null) {
            headerMap.put("userid", userId);
        }

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = recommendMasterListApiUrl();
                returnString = OKHttpUtil.downWithGetMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            MasterResultInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, MasterResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage()) ||
                    resultInfo.getResponse() == null) {
                return null;
            } else {
                return resultInfo.getResponse();
            }
        }
    }

    //首页消息列表
    public List<PushMsgInfo> getPushMessageList(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = getPushMessageListUrl();
                returnString = OKHttpUtil.downWithGetMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            PushMsgListResultInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, PushMsgListResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage()) ||
                    resultInfo.getResponse() == null) {
                return null;
            } else {
                List<PushMsgInfo> info = resultInfo.getResponse();
                return info;
            }
        }
    }

    //首页签到
    public CommonInfo signedIn() {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = signedInUrl();
                returnString = OKHttpUtil.downWithPostMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            CommonInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, CommonInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage())) {
                return null;
            } else {
                return resultInfo;
            }
        }
    }

    //搜索师傅列表
    public List<MasterInfo> getSearchMasterList(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = searchMasterListApiUrl();
                returnString = OKHttpUtil.downWithGetMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            MasterResultInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, MasterResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage()) ||
                    resultInfo.getResponse() == null) {
                return null;
            } else {
                return resultInfo.getResponse();
            }
        }
    }

    //师傅列表
    public List<MasterInfo> getMasterList(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = masterListApiUrl();
                returnString = OKHttpUtil.downWithGetMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            MasterResultInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, MasterResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage()) ||
                    resultInfo.getResponse() == null) {
                return null;
            } else {
                return resultInfo.getResponse();
            }
        }
    }

    //师傅详情
    public List<CommentInfo> getMasterCommentsInfo(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = masterCommentListApiUrl();
                returnString = OKHttpUtil.downWithGetMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            CommentListResultInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, CommentListResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage()) ||
                    resultInfo.getResponse() == null) {
                return null;
            } else {
                return resultInfo.getResponse();
            }
        }
    }

    //我的订单列表
    public List<OrderInfo> getMyOrderList(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = myOrderListApiUrl();
                returnString = OKHttpUtil.downWithGetMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            OrderResultInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, OrderResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage()) ||
                    resultInfo.getResponse() == null) {
                return null;
            } else {
                List<OrderInfo> info = resultInfo.getResponse();
                return info;
            }
        }
    }

    //取消订单
    public CommonInfo cancelOrderAction(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = cancelOrderApiUrl();
                returnString = OKHttpUtil.downWithPostJsonMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            CommonInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, CommonInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage())) {
                return null;
            } else {
                return resultInfo;
            }
        }
    }

    //订单详情
    public OrderDetailInfo getOrderDetailInfo(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = orderDetailApiUrl();
                returnString = OKHttpUtil.downWithGetMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            OrderDetailResultInfo resultInfo = null;
            try {
                returnString = returnString.replace("\"servicepro\":\"\"", "\"servicepro\":null");
                returnString = returnString.replace("\"masterInfo\":\"\"", "\"masterInfo\":null");
                resultInfo = new Gson().fromJson(returnString, OrderDetailResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage())
                    || resultInfo.getResponse() == null) {
                return null;
            } else {
                return resultInfo.getResponse();
            }
        }
    }

    //用户下单
    public CommonInfo userOrder(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = orderActionApiUrl();
                returnString = OKHttpUtil.downWithPostJsonMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            CommonInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, CommonInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage())) {
                return null;
            } else {
                return resultInfo;
            }
        }
    }

    //获取素有的安装方式列表
    public List<InstallMethodInfo> getInstallMethodList(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = installMethodListApiUrl();
                returnString = OKHttpUtil.downWithGetMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            InstallMethodResultInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, InstallMethodResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage()) ||
                    resultInfo.getResponse() == null) {
                return null;
            } else {
                return resultInfo.getResponse();
            }
        }
    }

    //获取所有的安装类型列表
    public List<InstallTypeInfo> getInstallTypeList(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = installTypeListApiUrl();
                returnString = OKHttpUtil.downWithGetMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            InstallTypeResultInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, InstallTypeResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage()) ||
                    resultInfo.getResponse() == null) {
                return null;
            } else {
                return resultInfo.getResponse();
            }
        }
    }

    //获取所有的安装材料列表
    public List<InstallMaterialInfo> getInstallMaterialList(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = installMaterialListApiUrl();
                returnString = OKHttpUtil.downWithGetMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            InstallMaterialResultInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, InstallMaterialResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage()) ||
                    resultInfo.getResponse() == null) {
                return null;
            } else {
                return resultInfo.getResponse();
            }
        }
    }

    //获取所有的安装材料价格列表
    public List<InstallMaterialPriceInfo> getInstallMaterialPriceList(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = installMaterialPriceListApiUrl();
                returnString = OKHttpUtil.downWithGetMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            InstallMaterialPriceResultInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, InstallMaterialPriceResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage()) ||
                    resultInfo.getResponse() == null) {
                return null;
            } else {
                return resultInfo.getResponse();
            }
        }
    }

    //获取安装商品列表
    public List<InstallShopInfo> getInstallShopList(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = installShopListApiUrl();
                returnString = OKHttpUtil.downWithGetMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            ShopResultInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, ShopResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage()) ||
                    resultInfo.getResponse() == null) {
                return null;
            } else {
                List<InstallShopInfo> info = resultInfo.getResponse();
                return info;
            }
        }
    }

    //上传图片
    public List<String> uploadImages(List<String> filePaths) {
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = uploadImageUrl();
                returnString = OKHttpUtil.uploadFile(urlStr, filePaths, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            UploadImgResultInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, UploadImgResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage()) ||
                    resultInfo.getResponse() == null) {
                return null;
            } else {
                UploadImgInfo info = resultInfo.getResponse();
                if (info != null && info.getFilePath() != null) {
                    List<String> pathList = new ArrayList<String>();
                    String imagePaths = info.getFilePath();
                    if (!imagePaths.trim().equalsIgnoreCase("")) {
                        String[] pathArray = imagePaths.split("\\;");
                        for (int i = 0, n = pathArray.length; i < n; i++) {
                            String pathStr = pathArray[i].trim();
                            if (!pathStr.equalsIgnoreCase("")) {
                                pathList.add(pathStr);
                            }
                        }
                    }
                    return pathList;
                } else {
                    return null;
                }
            }
        }
    }

    //获取上海所有的区县信息
    public List<AreaInfo> getAllArea() {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = getAllAreaUrl();
                returnString = OKHttpUtil.downWithGetMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            AreaResultInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, AreaResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage()) ||
                    resultInfo.getResponse() == null) {
                return null;
            } else {
                List<AreaInfo> info = resultInfo.getResponse();
                return info;
            }
        }
    }

    //意见反馈
    public CommonInfo feedbackAction(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = feedbackApiUrl();
                returnString = OKHttpUtil.downWithPostJsonMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            CommonInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, CommonInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage())) {
                return null;
            } else {
                return resultInfo;
            }
        }
    }

    //根据师傅id获取师傅信息
    public MasterInfoByOrderId getMasterInfoByOrderid(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = getMasterInfoByOrderidUrl();
                returnString = OKHttpUtil.downWithGetMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            MasterInfoByOrderIdResultInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, MasterInfoByOrderIdResultInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage()) ||
                    resultInfo.getResponse() == null) {
                return null;
            } else {
                MasterInfoByOrderId info = resultInfo.getResponse();
                return info;
            }
        }
    }

    //对订单进行评价
    public CommonInfo commentOrder(Map<String, String> params) {
        Map<String, String> paramMap = APIConfig.getHeaderPar() != null ? (Map<String, String>) APIConfig.getHeaderPar().clone() : new LinkedHashMap<String, String>();
        //TODO -- 添加参数
        if (params != null && params.size() > 0) {
            paramMap.putAll(params);
        }
        Map<String, String> headerMap = new HashMap<>();
        String token = SystemContext.getInstance().getToken();
        String userId = SystemContext.getInstance().getUserId();
        headerMap.put("token", token);
        headerMap.put("userid", userId);

        String returnString = null;
        if (OKHttpUtil.isNetworkAvailable(SystemContext.getInstance().getContext())) {
            try {
                String urlStr = commentOrderUrl();
                returnString = OKHttpUtil.downWithPostJsonMethod(urlStr, paramMap, headerMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //若返回为null,则是网络错误
        if (returnString == null || returnString.equalsIgnoreCase("")) {
            return null;
        } else {
            CommonInfo resultInfo = null;
            try {
                resultInfo = new Gson().fromJson(returnString, CommonInfo.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (resultInfo == null || CommonErrorHandler.getInstance().isError(resultInfo.getStatus(), resultInfo.getMessage())) {
                return null;
            } else {
                return resultInfo;
            }
        }
    }
}
